%icremed
% 2/11/97
% creates mean and median real scores for each year
% does the same for nominal scores too
% Modified by Dave Primo 7/2000

yreal = (y-aNs)./bNs;

%%%%%%%%%%%%%%  create House means and medians for each year  %%%%%%%%

hmed = [];
hmean = [];
hnommed = [];
hnommean = [];
for ttt = BeginYear:HEndYear,
  tind = find(t==ttt);
  curmean = sum( yreal(tind) ) / length(tind);
  hmean = [hmean;curmean];
  curmean = sum( y(tind) ) / length(tind);
  hnommean = [hnommean;curmean];

  yreatem = sort(yreal(tind));
  %lab1 = round(length(tind)/2);
  %lab2 = fix(length(tind)/2);
  lab1 = round( (length(tind)/2 + 1) );
  lab2 = fix( (length(tind)/2 + 1) );
  curmed = ( yreatem(lab1) + yreatem(lab2) )/2;
  hmed = [hmed;curmed];

  ytem = sort(y(tind));
  lab1 = round( (length(tind)/2 + 1) );
  lab2 = fix( (length(tind)/2 + 1) );
  curmed = ( ytem(lab1) + ytem(lab2) )/2;
  hnommed = [hnommed;curmed];
end;


smed = [];
smean = [];
snommed = [];
snommean = [];
for ttt = (HEndYear+1):EndYear,
  tind = find(t==ttt);
  curmean = sum( yreal(tind) ) / length(tind);
  smean = [smean;curmean];
  curmean = sum( y(tind) ) / length(tind);
  snommean = [snommean;curmean];

  yreatem = sort(yreal(tind));
  %lab1 = round(length(tind)/2);
  %lab2 = fix(length(tind)/2);
  lab1 = round( (length(tind)/2 + 1) );
  lab2 = fix( (length(tind)/2 + 1) );
  curmed = ( yreatem(lab1) + yreatem(lab2) )/2;
  smed = [smed;curmed];

  ytem = sort(y(tind));
  lab1 = round( (length(tind)/2 + 1) );
  lab2 = fix( (length(tind)/2 + 1) );
  curmed = ( ytem(lab1) + ytem(lab2) )/2;
  snommed = [snommed;curmed];
end;

%ayear = [(47:61),(63:96)]';
%ayear = [(59:61),(63:80)]';
ayear=[(71:99)]';

disp(' year sen mean   sen med  hou mean  hou med');
ymed = [ayear, smean, smed, hmean, hmed]

disp(' year  hou_nom_mean hou_rea_mean  hou_nom_med hou_rea_med');
ymed1 = [ayear, hnommean, hmean, hnommed, hmed]

disp(' year  sen_nom_mean sen_rea_mean  sen_nom_med sen_rea_med');
ymed2 = [ayear, snommean, smean, snommed, smed]

%ahou = a(1:49);
%bhou = b(1:49);
%asen = a(50:98);
%bsen = b(50:98);
%ab = [ayear, ahou, bhou, asen, bsen]

%save ab.dat ab /ascii;
%!copy ab.dat a:


%xx = [chamber, t, icpsr, st, pty, y, yreal];
save medhouseacu7199.txt ymed1 /ascii;
save medsenateacu7199.txt ymed2 /ascii;
